package utility;

import static org.junit.Assert.*;

import java.io.IOException;
import java.text.ParseException;



//import java.io.File;

import org.junit.Test;


public class EditorTest {

	@Test
	public void test(){
		
		UserInput testAdd1 = new UserInput(); testAdd1.startD = "20/11/12"; testAdd1.endD = "21/11/12"; testAdd1.endT = "1300"; testAdd1.task= "Consultation"; testAdd1.panelNumber = 0;
		UserInput testAdd2 = new UserInput(); testAdd2.startD = "30/11/12"; testAdd2.endD = "01/12/12";testAdd2.startT = "1200"; testAdd2.endT = "1300"; testAdd2.task= "Tuition";  testAdd2.panelNumber = 0;
		UserInput testAdd3 = new UserInput(); testAdd3.endD = "12/11/12";testAdd3.startT = "1200"; testAdd3.endT = "1300"; testAdd3.task= "Lunch with Jason"; testAdd3.panelNumber = 0;
		UserInput testAdd4 = new UserInput(); testAdd4.task= "Sky diving."; testAdd4.panelNumber = 0;
		UserInput testAdd5 = new UserInput(); testAdd5.startD = "01/12/12"; testAdd5.endD = "06/12/12"; testAdd5.task= "Camp"; testAdd5.panelNumber = 0;
		UserInput testAdd6 = new UserInput(); testAdd6.endD = "30/11/12";testAdd6.task= "Submit Assignment"; testAdd6.panelNumber = 0;
		UserInput testAdd7 = new UserInput();  testAdd7.endD = "20/11/12";testAdd7.endT = "1200"; testAdd7.task= "Submit Essay"; testAdd7.panelNumber = 0;
		
		Editor editor = new Editor();
		editor.setEnvironmentForTest();
		editor.initEditor();
	
		try {
			//add a floating task
			editor.addTask(testAdd4);
			//add a deadline task
			editor.addTask(testAdd6);
			//add a timed Task
			editor.addTask(testAdd2);
			editor.retrieveTasks();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}	
		assertEquals("check display after add","30/11/12;01/12/12;1200;1300;Tuition-;30/11/12;-;-;Submit Assignment-;-;-;-;Sky diving.",editor.jUnitTest());
		
		//display functions	
		try {
			UserInput inputs = new UserInput(); inputs.displayType = "r"; inputs.endD = "30/11/12"; inputs.panelNumber = 0;
			editor.displayTasks(inputs);
			assertEquals("check display dateRange","30/11/12;01/12/12;1200;1300;Tuition-;30/11/12;-;-;Submit Assignment",editor.jUnitTest());
			inputs = new UserInput(); inputs.displayType = "f"; inputs.panelNumber = 0;
			editor.displayTasks(inputs);
			assertEquals("check display floating","-;-;-;-;Sky diving.",editor.jUnitTest());
			inputs = new UserInput(); inputs.displayType = "a"; inputs.panelNumber = 0;
			editor.displayTasks(inputs);
			assertEquals("check display allTask","30/11/12;01/12/12;1200;1300;Tuition-;30/11/12;-;-;Submit Assignment-;-;-;-;Sky diving.",editor.jUnitTest());
		} catch (ParseException e) {		
			e.printStackTrace();
		}
			
		//delete functions

		try {
			UserInput inputs = new UserInput(); inputs.rowNumber = 2;inputs.panelNumber = 0;
			editor.deleteTask(inputs);
			assertEquals("check delete row 2","30/11/12;01/12/12;1200;1300;Tuition-;-;-;-;Sky diving.",editor.jUnitTest());		
			editor.addTask(testAdd7);
			//to refresh the display vector
			editor.retrieveTasks();
			assertEquals("check add 1 more data","-;20/11/12;-;1200;Submit Essay30/11/12;01/12/12;1200;1300;Tuition-;-;-;-;Sky diving.",editor.jUnitTest());	
			inputs.rowNumber = 5;
			editor.deleteTask(inputs);
			assertEquals("check delete out of range","-;20/11/12;-;1200;Submit Essay30/11/12;01/12/12;1200;1300;Tuition-;-;-;-;Sky diving.",editor.jUnitTest());	
		} catch (IOException e) {
			e.printStackTrace();
		}catch (ParseException e) {
			e.printStackTrace();
		}
			
		//edit Functions
		try {
			UserInput inputs = new UserInput(); inputs.displayType = "f";inputs.panelNumber = 0;
			editor.displayTasks(inputs);
			inputs = new UserInput(); inputs.rowNumber = 1; inputs.panelNumber = 0; inputs.endD = "20/11/12"; inputs.startD = "19/11/12"; inputs.startT = "1200";inputs.endT = "1300"; inputs.task = "swimming";
			editor.editTask(inputs);
			editor.retrieveTasks();
			assertEquals("check curr displaying vector after edit","",editor.jUnitTest());
			inputs = new UserInput(); inputs.displayType = "a"; inputs.panelNumber = 0;
			editor.displayTasks(inputs);
			assertEquals("check display all tasks","19/11/12;20/11/12;1200;1300;swimming-;20/11/12;-;1200;Submit Essay30/11/12;01/12/12;1200;1300;Tuition",editor.jUnitTest());
			inputs = new UserInput(); inputs.rowNumber = 2; inputs.startT= "-"; inputs.endT = "-";
			editor.editTask(inputs);
			editor.retrieveTasks();
			inputs = new UserInput(); inputs.rowNumber = 2; inputs.startT = "1200";
			editor.editTask(inputs);
			assert false;
			System.out.println("cannot be here.");
		} catch (ParseException e) {
			
			e.printStackTrace();
		} catch (IOException e) {
		
			e.printStackTrace();
		} catch (InvalidOperationException e) {
			
			e.printStackTrace();
		}
		
		//search Function
			UserInput inputs = new UserInput(); inputs.keyword = "s"; inputs.panelNumber = 0;
			editor.searchWord(inputs);
			assertEquals("check search","19/11/12;20/11/12;1200;1300;swimming-;20/11/12;-;1200;Submit Essay",editor.jUnitTest());
		//	UserInput inputs = new UserInput(); 
		
	
	}

}
